import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/29 8:31
 * @description Map计数
 */
public class Solution {
    public static void main(String[] args) {

    }
    public String largestWordCount(String[] messages, String[] senders) {
        Map<String, Integer> map = new HashMap<>();
        int n = messages.length;
        String ans = "";
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            String message = messages[i];
            String[] word = message.split(" ");
            map.put(senders[i], map.getOrDefault(senders[i], 0) + word.length);
        }
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            String temp = entry.getKey();
            int num = entry.getValue();
            if (ans == "" || num > cnt) {
                ans = temp;
                cnt = num;
            }else if (num == cnt && temp.compareTo(ans) > 0){
                ans = temp;
            }
        }
        return ans;
    }
}
